package com.huazai.lock;

/**
 * @author huazai
 * @date 2024/2/2
 */
public class SaleTick {
    public static void main(String[] args) {
        final Tick tick = new Tick();
        new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                tick.sale();
            }
        }, "aa").start();
        new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                tick.sale();
            }
        }, "bb").start();
        new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                tick.sale();
            }
        }, "cc").start();
    }
}

class Tick{
    private int number = 30;

    public synchronized void sale() {
        number--;
        if (number > 0) {
            System.out.println("number = " + Thread.currentThread().getName()
                    + " 卖出：" + number);
        }

    }
}
